package main

import (
	"fmt"
)

//map s示例  map引用类型

//声明
var map1 map[string]string
var map2 map[int]string
var map3 map[string]int
var map4 map[string]map[string]string

func testMap() {
	var a map[string]string
	a = make(map[string]string)
	a["a"] = "a"
	a["b"] = "b"
	a["c"] = "c"
	a["d"] = "d"
	a["e"] = "e"
	a["f"] = "f"
	fmt.Println(a, len(a))
	for k, v := range a {
		fmt.Println(k, v)
	}
}

func testMap2() {
	a := make(map[string]map[string]int, 1)
	a["student"] = map[string]int{"d": 3}
	a["student"] = map[string]int{"d1": 4}
	a["student"] = map[string]int{"d2": 5}
	fmt.Println(a)
	b, ok := a["student"]
	if ok {
		fmt.Println(b)
	} else {
		fmt.Println("不存在")
	}
	delete(a["student"], "d")
	fmt.Println(a)
}
func testMap3() {
	a := make(map[string]map[string]string)

	_, ok := a["zhangsan"]
	if !ok {
		fmt.Println("初始化张三")
		a["zhangsan"] = make(map[string]string)
	}
	a["zhangsan"]["name"] = "张三"
	a["zhangsan"]["password"] = "123456"
	a["zhangsan"]["age"] = "18"
	for _, v := range a {
		for _, v1 := range v {
			fmt.Println(v1)
		}
	}
	delete(a["zhangsan"], "age")
	fmt.Println(len(a))
	for _, v := range a {
		for _, v1 := range v {
			fmt.Println(v1)
		}

	}
}

func main() {
	testMap3()
}
